import request from "@/request/request.js";

// 获取所有商品列表
export const getGoodsList = ()=> {
    return request.get('goods/goods/getAll')
}

//搜索商品
export const searchGoods = (goodsName)=> {
    let params = new URLSearchParams()
    params.append('name', goodsName)
  return request.get('goods/goods/getOne', {params})
}

//获取单个商品信息
export const getGoodsInfo = (goodsId)=> {
    return request.get('goods/goods/detail', {params: {gid: goodsId}})
}

//加入购物车
export const addCart = (goodsInfo,number)=> {
    let params = new URLSearchParams()
    params.append('goodsname', goodsInfo.gname)
    params.append('price', goodsInfo.gprice)
    params.append('goodsId', goodsInfo.gid)
    params.append('number', number)
    return request.get('goods/goods/addCart', {params})
}

//查询购物车
export const getCart = ()=> {
    return request.get('/goods/goods/getAllCart')
}

//删除购物车
export const deleteCart = (cartId)=> {
    let params = new URLSearchParams()
    params.append('cartId', cartId)
    return request.get('/goods/goods/deleteCart', {params})
}

//确认购买
export const confirmPayGoods = (payGoodsData)=> {
    let params = new URLSearchParams()
    params.append('goodid',payGoodsData.goodid)
    params.append('number',payGoodsData.number)
    params.append('cartId',payGoodsData.cartId)
    return request.get('goods/goods/payGoods', {params})
}

//获取订单
export const getOrder = ()=> {
    return request.get('goods/goods/getAllOrder')
}

//单次修改购物车数量
export const editCartNum = (cartId,number)=> {
    let params = new URLSearchParams()
    params.append('number',number)
    params.append('cartId',cartId)
    return request.get('goods/goods/editCartNum', {params})
}